package org.rsbot.gui;

import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JSeparator;
import org.rsbot.bot.Bot;
import org.rsbot.event.impl.DrawBoundaries;
import org.rsbot.event.impl.DrawInventory;
import org.rsbot.event.impl.DrawItems;
import org.rsbot.event.impl.DrawModel;
import org.rsbot.event.impl.DrawMouse;
import org.rsbot.event.impl.DrawNPCs;
import org.rsbot.event.impl.DrawObjects;
import org.rsbot.event.impl.DrawPlayers;
import org.rsbot.event.impl.DrawSettings;
import org.rsbot.event.impl.MessageLogger;
import org.rsbot.event.impl.TAnimation;
import org.rsbot.event.impl.TCamera;
import org.rsbot.event.impl.TFPS;
import org.rsbot.event.impl.TFloorHeight;
import org.rsbot.event.impl.TLoginIndex;
import org.rsbot.event.impl.TMenu;
import org.rsbot.event.impl.TMenuActions;
import org.rsbot.event.impl.TMousePosition;
import org.rsbot.event.impl.TPlayerPosition;
import org.rsbot.event.impl.TTab;
import org.rsbot.event.impl.TUserInputAllowed;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.event.listeners.TextPaintListener;

public class BotMenuBar extends JMenuBar
{
  private static final long serialVersionUID = 971579975301998332L;
  public static final Map<String, Class<?>> DEBUG_MAP = new LinkedHashMap();
  public static final String[] TITLES;
  public static final String[][] ELEMENTS;
  private Map<String, JCheckBoxMenuItem> eventCheckMap = new HashMap();
  private Map<String, JCheckBoxMenuItem> commandCheckMap = new HashMap();
  private Map<String, JMenuItem> commandMenuItem = new HashMap();
  private ActionListener listener;

  private static String[] constructDebugs()
  {
    ArrayList localArrayList = new ArrayList();
    localArrayList.add("Hide Toolbar");
    localArrayList.add("Hide Log Window");
    localArrayList.add("All Debugging");
    localArrayList.add("-");
    for (Object localObject = DEBUG_MAP.keySet().iterator(); ((Iterator)localObject).hasNext(); ) { str = (String)((Iterator)localObject).next();
      localClass = (Class)DEBUG_MAP.get(str);
      if (PaintListener.class.isAssignableFrom(localClass))
        localArrayList.add(str);
    }
    String str;
    Class localClass;
    localArrayList.add("-");
    for (localObject = DEBUG_MAP.keySet().iterator(); ((Iterator)localObject).hasNext(); ) { str = (String)((Iterator)localObject).next();
      localClass = (Class)DEBUG_MAP.get(str);
      if (TextPaintListener.class.isAssignableFrom(localClass)) {
        localArrayList.add(str);
      }
    }
    localArrayList.add("-");
    for (localObject = DEBUG_MAP.keySet().iterator(); ((Iterator)localObject).hasNext(); ) { str = (String)((Iterator)localObject).next();
      localClass = (Class)DEBUG_MAP.get(str);
      if ((!TextPaintListener.class.isAssignableFrom(localClass)) && (!PaintListener.class.isAssignableFrom(localClass))) {
        localArrayList.add(str);
      }
    }
    for (localObject = localArrayList.listIterator(); ((ListIterator)localObject).hasNext(); ) {
      str = (String)((ListIterator)localObject).next();
      if (!str.equals("-")) {
        ((ListIterator)localObject).set("ToggleF " + str);
      }
    }
    return (String)(String[])localArrayList.toArray(new String[localArrayList.size()]);
  }

  public BotMenuBar(ActionListener paramActionListener)
  {
    this.listener = paramActionListener;
    for (int i = 0; i < TITLES.length; i++) {
      String str = TITLES[i];
      String[] arrayOfString = ELEMENTS[i];
      add(constructMenu(str, arrayOfString));
    }
  }

  public void setOverrideInput(boolean paramBoolean) {
    ((JCheckBoxMenuItem)this.commandCheckMap.get("Force Input")).setSelected(paramBoolean);
  }

  public void setPauseScript(boolean paramBoolean) {
    ((JMenuItem)this.commandMenuItem.get("Pause Script")).setText(paramBoolean ? "Resume Script" : "Pause Script");
  }

  public void setBot(Bot paramBot)
  {
    Object localObject;
    if (paramBot == null) {
      ((JMenuItem)this.commandMenuItem.get("Close Bot")).setEnabled(false);
      ((JMenuItem)this.commandMenuItem.get("Run Script")).setEnabled(false);
      ((JMenuItem)this.commandMenuItem.get("Stop Script")).setEnabled(false);
      ((JMenuItem)this.commandMenuItem.get("Pause Script")).setEnabled(false);
      ((JMenuItem)this.commandMenuItem.get("Save Screenshot")).setEnabled(false);
      for (Iterator localIterator = this.eventCheckMap.values().iterator(); localIterator.hasNext(); ) { localObject = (JCheckBoxMenuItem)localIterator.next();
        ((JCheckBoxMenuItem)localObject).setSelected(false);
        ((JCheckBoxMenuItem)localObject).setEnabled(false);
      }
      disable(new String[] { "All Debugging", "Force Input", "Less CPU", "Disable Anti-Randoms", "Disable Auto Login" });
    }
    else {
      ((JMenuItem)this.commandMenuItem.get("Close Bot")).setEnabled(true);
      ((JMenuItem)this.commandMenuItem.get("Run Script")).setEnabled(true);
      ((JMenuItem)this.commandMenuItem.get("Stop Script")).setEnabled(true);
      ((JMenuItem)this.commandMenuItem.get("Pause Script")).setEnabled(true);
      ((JMenuItem)this.commandMenuItem.get("Save Screenshot")).setEnabled(true);
      int i = 0;
      for (localObject = this.eventCheckMap.entrySet().iterator(); ((Iterator)localObject).hasNext(); ) { Map.Entry localEntry = (Map.Entry)((Iterator)localObject).next();
        ((JCheckBoxMenuItem)localEntry.getValue()).setEnabled(true);
        boolean bool = paramBot.hasListener((Class)DEBUG_MAP.get(localEntry.getKey()));
        ((JCheckBoxMenuItem)localEntry.getValue()).setSelected(bool);
        if (bool) {
          i++;
        }
      }
      enable("All Debugging", i == this.eventCheckMap.size());
      enable("Mouse", true);
      enable("Force Input", paramBot.overrideInput);
      enable("Less CPU", paramBot.disableRendering);
      enable("Disable Anti-Randoms", paramBot.disableRandoms);
      enable("Disable Auto Login", paramBot.disableAutoLogin);
    }
  }

  public JCheckBoxMenuItem getCheckBox(String paramString) {
    return (JCheckBoxMenuItem)this.commandCheckMap.get(paramString);
  }

  private void disable(String[] paramArrayOfString) {
    for (String str : paramArrayOfString) {
      ((JCheckBoxMenuItem)this.commandCheckMap.get(str)).setSelected(false);
      ((JCheckBoxMenuItem)this.commandCheckMap.get(str)).setEnabled(false);
    }
  }

  private void enable(String paramString, boolean paramBoolean)
  {
    ((JCheckBoxMenuItem)this.commandCheckMap.get(paramString)).setSelected(paramBoolean);
    ((JCheckBoxMenuItem)this.commandCheckMap.get(paramString)).setEnabled(true);
  }

  private JMenu constructMenu(String paramString, String[] paramArrayOfString) {
    JMenu localJMenu = new JMenu(paramString);
    for (String str : paramArrayOfString) {
      if (str.equals("-")) {
        localJMenu.add(new JSeparator());
      }
      else
      {
        Object localObject;
        if (str.startsWith("Toggle")) {
          str = str.substring("Toggle".length());
          int k = str.charAt(0);
          str = str.substring(2);
          localObject = new JCheckBoxMenuItem(str);
          if ((k == 116) || (k == 84)) {
            ((JMenuItem)localObject).setSelected(true);
          }
          if (DEBUG_MAP.containsKey(str)) {
            localJCheckBoxMenuItem = (JCheckBoxMenuItem)localObject;
            this.eventCheckMap.put(str, localJCheckBoxMenuItem);
          }
          JCheckBoxMenuItem localJCheckBoxMenuItem = (JCheckBoxMenuItem)localObject;
          this.commandCheckMap.put(str, localJCheckBoxMenuItem);
        } else {
          localObject = new JMenuItem(str);

          this.commandMenuItem.put(str, localObject);
        }
        ((JMenuItem)localObject).addActionListener(this.listener);
        ((JMenuItem)localObject).setActionCommand(paramString + "." + str);
        localJMenu.add((JMenuItem)localObject);
      }
    }
    return (JMenu)localJMenu;
  }

  static
  {
    DEBUG_MAP.put("Game State", TLoginIndex.class);
    DEBUG_MAP.put("Current Tab", TTab.class);
    DEBUG_MAP.put("Camera", TCamera.class);
    DEBUG_MAP.put("Animation", TAnimation.class);
    DEBUG_MAP.put("Floor Height", TFloorHeight.class);
    DEBUG_MAP.put("Player Position", TPlayerPosition.class);
    DEBUG_MAP.put("Mouse Position", TMousePosition.class);
    DEBUG_MAP.put("User Input Allowed", TUserInputAllowed.class);
    DEBUG_MAP.put("Menu Actions", TMenuActions.class);
    DEBUG_MAP.put("Menu", TMenu.class);
    DEBUG_MAP.put("FPS", TFPS.class);

    DEBUG_MAP.put("Players", DrawPlayers.class);
    DEBUG_MAP.put("NPCs", DrawNPCs.class);
    DEBUG_MAP.put("Objects", DrawObjects.class);
    DEBUG_MAP.put("Models", DrawModel.class);
    DEBUG_MAP.put("Mouse", DrawMouse.class);
    DEBUG_MAP.put("Inventory", DrawInventory.class);
    DEBUG_MAP.put("Ground Items", DrawItems.class);
    DEBUG_MAP.put("Calc Test", DrawBoundaries.class);
    DEBUG_MAP.put("Settings", DrawSettings.class);

    DEBUG_MAP.put("Log Messages", MessageLogger.class);

    TITLES = new String[] { "File", "Edit", "View", "Help", "Layout" };
    ELEMENTS = new String[][] { { "New Bot", "Close Bot", "-", "Run Script", "Stop Script", "Pause Script", "-", "Snap to Tray", "Save Screenshot", "-", "Exit" }, { "Accounts", "-", "ToggleF Force Input", "ToggleF Less CPU", "-", "ToggleF Disable Anti-Randoms", "ToggleF Disable Auto Login" }, constructDebugs(), { "Site", "Project", "About" }, { "Themes" } };
  }
}